package com.mike.spring.CustomEditor;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.factory.config.CustomEditorConfigurer;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.beans.propertyeditors.PropertiesEditor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.HashMap;
import java.util.Map;

public class MainClass {
    public static void main(String[] args) {
//        ApplicationContext context = new ClassPathXmlApplicationContext("/com/mike/spring/CustomEditor/beans.xml");
//        DateClass dateClass = (DateClass) context.getBean("dateClass");
//        System.out.println("args = [" + JSON.toJSONString(dateClass) + "]");

        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
        XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(factory);
        beanDefinitionReader.loadBeanDefinitions("/com/mike/spring/CustomEditor/beans.xml");
        CustomEditorConfigurer customEditorConfigurer = new CustomEditorConfigurer();
        Map customerEditors = new HashMap();
        customerEditors.put("java.util.Date", new DateEditor());
        customEditorConfigurer.setCustomEditors(customerEditors);
        customEditorConfigurer.postProcessBeanFactory(factory);
        DateClass dateClass = (DateClass) factory.getBean("dateClass");
        System.out.println("args = [" + JSON.toJSONString(dateClass) + "]");
    }
}
